package com.example.finalproject;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import java.util.ArrayList;

public class Details extends AppCompatActivity {

    SQLiteDatabase db1;
    SQLiteDatabase db2;
    ContentValues cv1;
    ContentValues cv2;
    String name;
    String material;
    String step;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        Intent intent = getIntent();
        name = intent.getStringExtra("name_key");
        material = intent.getStringExtra("material_key");
        step = intent.getStringExtra("step_key");
        TextView tv1 = findViewById(R.id.d_name);
        tv1.setText(name);
        TextView tv2 = findViewById(R.id.d_material);
        tv2.setText(material);
        TextView tv3 = findViewById(R.id.d_step);
        tv3.setText(step);

        MyLikeOpenHelper openHelper=new MyLikeOpenHelper(this,"like_list.db",null,1);
        db1 = openHelper.getWritableDatabase();
        cv1 =new ContentValues();

        MyCollectOpenHelper helper =new MyCollectOpenHelper(this,"collect_list.db",null,1);
        db2 = helper.getWritableDatabase();
        cv2 =new ContentValues();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.my_menu1,menu);
        return super.onCreateOptionsMenu(menu);
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.menu_like:

               cv1.put("name",name);
               cv1.put("material",material);
               cv1.put("step",step);
               db1.insert("like_list",null,cv1);
               Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();
                return true;
            case R.id.menu_collect:
                cv2.put("name",name);
                cv2.put("material",material);
                cv2.put("step",step);
                db2.insert("collect_list",null,cv2);
                Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

}